package EJB;

import coms.ejb.*;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.InitialContext;

public class EJBLocator {

    private static EJBLocator locator = new EJBLocator();
    private InitialContext ctx;
    public static final String USER_BEAN_LOOKUP_NAME = "UserBean";
    public static final String CONFERENCE_BEAN_LOOKUP_NAME = "ConferenceBean";
    public static final String CONFERENCE_REGISTRATION_BEAN_LOOKUP_NAME = "ConferenceRegistrationBean";
    public static final String CONFERENCE_ITEM_BEAN_LOOKUP_NAME = "ConferenceItemBean";
    public static final String CONFERENCE_ITEM_BOOKING_BEAN_LOOKUP_NAME = "ConferenceItemBookingBean";
    public static final String CONFERENCE_ITEM_TYPE_BEAN_LOOKUP_NAME = "ConferenceItemTypeBean";
    public static final String EVENT_BEAN_LOOKUP_NAME = "EventBean";
    public static final String KEYWORD_BEAN_LOOKUP_NAME = "KeywordBean";
    public static final String LOCATION_BEAN_LOOKUP_NAME = "LocationBean";    
    public static final String PRESENTATION_TYPE_BEAN_LOOKUP_NAME = "PresentationTypeBean";
    public static final String PUBLICATION_BEAN_LOOKUP_NAME = "PublicationBean";
    public static final String REVIEW_BEAN_LOOKUP_NAME = "ReviewBean";
    public static final String EMAIL_MDB_LOOKUP_NAME = "jms/EmailSenderMDB";
    public static final String EMAIL_FACTORY_LOOKUP_NAME = "jms/EmailSenderMDBFactory";

    private EJBLocator() {
        try {
            ctx = new InitialContext();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public InitialContext getInitialContext() {
        return ctx;
    }

    public static EJBLocator getInstance() {
        return locator;
    }

    public static UserBeanRemote lookupUserBean() throws Exception {
        try {
            return (UserBeanRemote) getInstance().getInitialContext().lookup(USER_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static QueueConnectionFactory lookupEmailFactory() throws Exception {
        try {
            return (QueueConnectionFactory) getInstance().getInitialContext().lookup(EMAIL_FACTORY_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    
    public static Queue lookupEmailMDB() throws Exception {
        try {
            return (Queue) getInstance().getInitialContext().lookup(EMAIL_MDB_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    
    public static ConferenceItemBookingBeanRemote lookupConferenceItemBookingBean() throws Exception {
        try {
            return (ConferenceItemBookingBeanRemote) getInstance().getInitialContext().lookup(CONFERENCE_ITEM_BOOKING_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static ConferenceBeanRemote lookupConferenceBean() throws Exception {
        try {
            return (ConferenceBeanRemote) getInstance().getInitialContext().lookup(CONFERENCE_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static ConferenceItemBeanRemote lookupConferenceItemBean() throws Exception {
        try {
            return (ConferenceItemBeanRemote) getInstance().getInitialContext().lookup(CONFERENCE_ITEM_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static PublicationBeanRemote lookupPublicationBean() throws Exception {
        try {
            return (PublicationBeanRemote) getInstance().getInitialContext().lookup(PUBLICATION_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static ReviewBeanRemote lookupReviewBean() throws Exception {
        try {
            return (ReviewBeanRemote) getInstance().getInitialContext().lookup(REVIEW_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static EventBeanRemote lookupEventBean() throws Exception {
        try {
            return (EventBeanRemote) getInstance().getInitialContext().lookup(EVENT_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static ConferenceRegistrationBeanRemote lookupConferenceRegistrationBean() throws Exception {
        try {
            return (ConferenceRegistrationBeanRemote) getInstance().getInitialContext().lookup(CONFERENCE_REGISTRATION_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static ConferenceItemTypeBeanRemote lookupConferenceItemTypeBean() throws Exception {
        try {
            return (ConferenceItemTypeBeanRemote) getInstance().getInitialContext().lookup(CONFERENCE_ITEM_TYPE_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static KeywordBeanRemote lookupKeywordBean() throws Exception {
        try {
            return (KeywordBeanRemote) getInstance().getInitialContext().lookup(KEYWORD_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static LocationBeanRemote lookupLocationBean() throws Exception {
        try {
            return (LocationBeanRemote) getInstance().getInitialContext().lookup(LOCATION_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    public static PresentationTypeBeanRemote lookupPresentationTypeBean() throws Exception {
        try {
            return (PresentationTypeBeanRemote) getInstance().getInitialContext().lookup(PRESENTATION_TYPE_BEAN_LOOKUP_NAME);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
